<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>如何通过Gradle构建SpringBoot应用 - Lglspace‘s Blog</title>
  <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="lglspace" /><meta name="description" content="参考地址 https://spring.io/guides/gs/rest-service/ 具体实践（以Gradle为例） 进入官网,选择相应配置，导出目录 https://start.spring.io/ 修改配制 1、采用本地Gradle 如果$PROJECT_HOME/g" /><meta name="keywords" content="lglspace, blog, lgl" />






<meta name="generator" content="Hugo 0.79.0 with theme even" />


<link rel="canonical" href="https://lglspace.cn/post/java/java-gradle-springboot/" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">



<link href="/sass/main.min.b5a744db6de49a86cadafb3b70f555ab443f83c307a483402259e94726b045ff.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">
<link rel="stylesheet" href="/css/even-custom.css">


<meta property="og:title" content="如何通过Gradle构建SpringBoot应用" />
<meta property="og:description" content="参考地址 https://spring.io/guides/gs/rest-service/ 具体实践（以Gradle为例） 进入官网,选择相应配置，导出目录 https://start.spring.io/ 修改配制 1、采用本地Gradle 如果$PROJECT_HOME/g" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://lglspace.cn/post/java/java-gradle-springboot/" />
<meta property="article:published_time" content="2020-11-03T14:23:26+08:00" />
<meta property="article:modified_time" content="2020-11-03T14:23:26+08:00" />
<meta itemprop="name" content="如何通过Gradle构建SpringBoot应用">
<meta itemprop="description" content="参考地址 https://spring.io/guides/gs/rest-service/ 具体实践（以Gradle为例） 进入官网,选择相应配置，导出目录 https://start.spring.io/ 修改配制 1、采用本地Gradle 如果$PROJECT_HOME/g">
<meta itemprop="datePublished" content="2020-11-03T14:23:26+08:00" />
<meta itemprop="dateModified" content="2020-11-03T14:23:26+08:00" />
<meta itemprop="wordCount" content="363">



<meta itemprop="keywords" content="java,gradle,springboot," />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="如何通过Gradle构建SpringBoot应用"/>
<meta name="twitter:description" content="参考地址 https://spring.io/guides/gs/rest-service/ 具体实践（以Gradle为例） 进入官网,选择相应配置，导出目录 https://start.spring.io/ 修改配制 1、采用本地Gradle 如果$PROJECT_HOME/g"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->

</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/" class="logo">Lglspace</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="/">
        <li class="mobile-menu-item">主页</li>
      </a><a href="/post/">
        <li class="mobile-menu-item">归档</li>
      </a><a href="/tags/">
        <li class="mobile-menu-item">标签</li>
      </a><a href="/categories/">
        <li class="mobile-menu-item">分类</li>
      </a>
  </ul>

  


</nav>

  <div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/" class="logo">Lglspace</a>
</div>





<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
        <a class="menu-item-link" href="/">主页</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/post/">归档</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/tags/">标签</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/categories/">分类</a>
      </li>
  </ul>
</nav>

    </header>

    <main id="main" class="main">
      <div class="content-wrapper">
        <div id="content" class="content">
          <article class="post">
    
    <header class="post-header">
      <h1 class="post-title">如何通过Gradle构建SpringBoot应用</h1>

      <div class="post-meta">
        <span class="post-time"> 2020-11-03 </span>
        <div class="post-category">
            <a href="/categories/java/"> java </a>
            </div>
        
      </div>
    </header>

    <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content always-active">
    <nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li><a href="#参考地址">参考地址</a></li>
        <li><a href="#具体实践以gradle为例">具体实践（以Gradle为例）</a>
          <ul>
            <li><a href="#进入官网选择相应配置导出目录">进入官网,选择相应配置，导出目录</a></li>
            <li><a href="#修改配制">修改配制</a></li>
            <li><a href="#intellij-idea设置gradle相关信息">IntelliJ IDEA设置gradle相关信息</a></li>
            <li><a href="#buildgradle文件添加相关配制">build.gradle文件添加相关配制</a></li>
            <li><a href="#启动">启动</a></li>
            <li><a href="#打jar包">打Jar包</a></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</nav>
  </div>
</div>
    <div class="post-content">
      <h2 id="参考地址">参考地址</h2>
<p><a href="https://spring.io/guides/gs/rest-service/">https://spring.io/guides/gs/rest-service/</a></p>
<h2 id="具体实践以gradle为例">具体实践（以Gradle为例）</h2>
<h3 id="进入官网选择相应配置导出目录">进入官网,选择相应配置，导出目录</h3>
<p><a href="https://start.spring.io/">https://start.spring.io/</a></p>
<h3 id="修改配制">修改配制</h3>
<h4 id="1采用本地gradle">1、采用本地Gradle</h4>
<ol>
<li>如果$PROJECT_HOME/gradle/wrapper/gradle-wrapper.properties中指定的版本不一致，需要执行下</li>
</ol>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash"> <span class="c1"># 在项目根目录下执行</span>
 ./gradlew wrapper --gradle-version<span class="o">=</span>6.7 --distribution-type<span class="o">=</span>bin
</code></pre></td></tr></table>
</div>
</div><ol start="2">
<li>执行</li>
</ol>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">./gradlew bootRun

# 执行此命令后，会有个downloading...，这时Ctrl+C，中止程序。
</code></pre></td></tr></table>
</div>
</div><ol start="3">
<li>复制下载好的文件</li>
</ol>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">cp gradle-6.7-bin.zip $GRADLE_USR_HOME\wrapper\dists\gradle-6.7-bin\{...}\
</code></pre></td></tr></table>
</div>
</div><ol start="4">
<li>再次执行</li>
</ol>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">./gradlew bootRun
</code></pre></td></tr></table>
</div>
</div><h3 id="intellij-idea设置gradle相关信息">IntelliJ IDEA设置gradle相关信息</h3>
<blockquote>
<p>配置下gradle user home 及 gradle本地安装目录</p>
</blockquote>
<h3 id="buildgradle文件添加相关配制">build.gradle文件添加相关配制</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">plugins {
	id &#39;org.springframework.boot&#39; version &#39;2.3.2.RELEASE&#39;
	id &#39;io.spring.dependency-management&#39; version &#39;1.0.8.RELEASE&#39;
	id &#39;java&#39;
}

group = &#39;com.example&#39;
version = &#39;0.0.1-SNAPSHOT&#39;
sourceCompatibility = &#39;1.8&#39;

repositories {
    // 添加阿里云仓库
    maven { url &#39;https://maven.aliyun.com/repository/public/&#39;}
	mavenLocal()
	mavenCentral()
}

dependencies {
	implementation &#39;org.springframework.boot:spring-boot-starter-web&#39;
	testImplementation(&#39;org.springframework.boot:spring-boot-starter-test&#39;) {
		exclude group: &#39;org.junit.vintage&#39;, module: &#39;junit-vintage-engine&#39;
	}
}

test {
	useJUnitPlatform()
}
</code></pre></td></tr></table>
</div>
</div><h3 id="启动">启动</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">./gradlew bootRun
</code></pre></td></tr></table>
</div>
</div><h3 id="打jar包">打Jar包</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">./gradlew build
</code></pre></td></tr></table>
</div>
</div>
    </div>

    <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">lglspace</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2020-11-03
        
    </span>
  </p>
  
  
</div>
<footer class="post-footer">
      <div class="post-tags">
          <a href="/tags/java/">java</a>
          <a href="/tags/gradle/">gradle</a>
          <a href="/tags/springboot/">springboot</a>
          </div>
      <nav class="post-nav">
        <a class="prev" href="/post/windows/cmd-relate/">
            <i class="iconfont icon-left"></i>
            <span class="prev-text nav-default">Windows命令行操作备忘</span>
            <span class="prev-text nav-mobile">上一篇</span>
          </a>
        <a class="next" href="/post/java/java-aliyun-relate/">
            <span class="next-text nav-default">阿里云Maven中央仓库配制</span>
            <span class="next-text nav-mobile">下一篇</span>
            <i class="iconfont icon-right"></i>
          </a>
      </nav>
    </footer>
  </article>
        </div>
        

  

  

      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
      <a href="mailto:lglspace@outlook.com" class="iconfont icon-email" title="email"></a>
  <a href="https://lglspace.cn/index.xml" type="application/rss+xml" class="iconfont icon-rss" title="rss"></a>
</div>

<div class="copyright">
  

  

  <span class="copyright-year">
    &copy; 
    2020 - 
    2021<span class="heart"><i class="iconfont icon-heart"></i></span><span>lglspace</span>
  </span>
</div>

    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>



<script type="text/javascript" src="/js/main.min.a74e82b84b872f6b028df4e965781ddbba1606f0253b4fad5e4cf3913cf576eb.js"></script>






<script src="/js/site-custom.js"></script>


</body>
</html>
